﻿CREATE PROCEDURE [dbo].[Clientes_DevolverPorId]

@IdCliente INT,
@IncluirImagen BIT

AS

IF(@IncluirImagen = 1)
BEGIN
	SELECT c.IdCliente, 
		c.IdRubroCliente, 
		c.IdTipoIva, 
		c.IdListaPrecioVenta, 
		c.IdVendedor, 
		c.Codigo, 
		c.Nombre, 
		c.LimiteDeuda, 
		c.Cuit, 
		c.Email, 
		c.SitioWeb, 
		c.Observaciones, 
		c.Imagen, 
		c.EstaEliminado
		FROM Clientes c
		WHERE c.IdCliente = @IdCliente
END
ELSE
BEGIN
	SELECT c.IdCliente, 
		c.IdRubroCliente, 
		c.IdTipoIva, 
		c.IdListaPrecioVenta, 
		c.IdVendedor, 
		c.Codigo, 
		c.Nombre, 
		c.LimiteDeuda, 
		c.Cuit, 
		c.Email, 
		c.SitioWeb, 
		c.Observaciones, 
		CASE WHEN c.Imagen IS NULL
			THEN NULL
			ELSE CONVERT(IMAGE, 0x) END AS Imagen,
		c.EstaEliminado
		FROM Clientes c
		WHERE c.IdCliente = @IdCliente
END

SELECT ctfp.IdCliente,
	ctfp.IdTipoFormaPago
	FROM ClientesTiposFormasPagos ctfp
	WHERE ctfp.IdCliente = @IdCliente

SELECT dc.IdDomicilioCliente, 
	dc.IdCliente, 
	dc.IdTipoDomicilio, 
	dc.IdBarrio, 
	dc.Calle, 
	dc.Numero, 
	dc.Piso, 
	dc.Departamento
	FROM DomiciliosClientes dc
	WHERE dc.IdCliente = @IdCliente

SELECT tc.IdTelefonoCliente, 
	tc.IdTipoTelefono, 
	tc.IdCliente, 
	tc.CodigoArea, 
	tc.Numero
	FROM TelefonosClientes tc
	WHERE tc.IdCliente = @IdCliente

SELECT ccpc.IdCliente,
	ccpc.IdCampoPersonalizadoCliente,
	ccpc.Valor
	FROM ClientesCamposPersonalizadosClientes ccpc
	WHERE ccpc.IdCliente = @IdCliente